//
//  NavigationView.m
//  GuoMei
//
//  Created by 王磊 on 2018/3/1.
//  Copyright © 2018年 王磊. All rights reserved.
//

#import "NavigationView.h"

#import "Masonry.h"


@interface NavigationView()
@property (nonatomic, strong) UIButton * leftBtn ;
@property (nonatomic, strong) UIButton * rightBtn ;
@property (nonatomic, strong) UIButton * secRightBtn ;
@property (nonatomic, strong) UIView * searchView ;
@property (nonatomic, strong) UIButton * searchBtn ;
@property (nonatomic, strong) UIButton * voiceBtn ;

@end
@implementation NavigationView

-(instancetype)initWithFrame:(CGRect)frame{
   self = [super initWithFrame:frame];
    if (self) {
        [self loadView];
    }
    return self;
}
-(void)loadView{
    _leftBtn = ({
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setBackgroundImage:[UIImage imageNamed:@"shouye_icon_scan_white"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(saoYiSaoClick) forControlEvents:UIControlEventTouchUpInside];
        btn;
    });
    
    _rightBtn = ({
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setBackgroundImage:[UIImage imageNamed:@"shouye_icon_sort_white"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(fenLeiClick) forControlEvents:UIControlEventTouchUpInside];
        btn;
    });
    
    _secRightBtn = ({
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setBackgroundImage:[UIImage imageNamed:@"icon_gouwuche_title_white"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(gouWuCheClick) forControlEvents:UIControlEventTouchUpInside];
        btn;
    });
    
    _searchView = [[UIView alloc]init];
    _searchView.backgroundColor = [UIColor whiteColor];
    _searchView.layer.cornerRadius = 16;
    _searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_searchBtn setTitle:@"彩电年终内购会" forState:UIControlStateNormal];
    [_searchBtn setImage:[UIImage imageNamed:@"group_home_search_gray"] forState:UIControlStateNormal];
    [_searchBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    _searchBtn.titleLabel.font = PFR13Font;
    //让按钮点亮和正常状态一样
    _searchBtn.adjustsImageWhenHighlighted = NO;
    _searchBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _searchBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);
    _searchBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [_searchView addSubview:_searchBtn];
    _voiceBtn = [[UIButton alloc]init];
    [_voiceBtn setImage:[UIImage imageNamed:@"icon_voice_search"] forState:UIControlStateNormal];
    [_searchView addSubview:_voiceBtn];
    [self addSubview:_secRightBtn];
    [self addSubview:_rightBtn];
    [self addSubview:_leftBtn];
    [self addSubview:_searchView];
}
#pragma -mark 布局
-(void)layoutSubviews{
    [super layoutSubviews];
    [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(20);
        make.left.equalTo(self.mas_left).offset(0);
        make.height.equalTo(@44);
        make.width.equalTo(@44);
    }];
    [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_leftBtn.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-0);
        make.height.equalTo(@44);
        make.width.equalTo(@44);
    }];
    [_secRightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_leftBtn.mas_centerY);
        make.right.equalTo(_rightBtn.mas_left).offset(5);
        make.height.equalTo(@44);
        make.width.equalTo(@44);
    }];
    [_searchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_leftBtn.mas_centerY);
        make.left.equalTo(_leftBtn.mas_right).offset(-5);
        make.right.equalTo(_secRightBtn.mas_left).offset(5);
        make.height.equalTo(@32);
    }];
    [_searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_searchView);
        make.top.mas_equalTo(_searchView);
        make.height.mas_equalTo(_searchView);
        make.right.equalTo(_searchView.mas_right).offset(-44);
    }];
    [_voiceBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_searchBtn.mas_right).offset(0);
        make.top.mas_equalTo(_searchView);
        make.height.mas_equalTo(_searchView);
        make.right.equalTo(_searchView.mas_right).offset(0);
    }];
}
#pragma -mark 按钮点击事件
-(void)saoYiSaoClick{
    !_leftItemClickBlock ? :_leftItemClickBlock();
}
-(void)fenLeiClick{
    !_rightItemClickBlock ? :_rightItemClickBlock();
}
-(void)gouWuCheClick{
    !_secRightItemClickBlock ? :_secRightItemClickBlock();
}
@end
